Skip to content

bpo-38735: Don't fail when importing from / with sys.pycache_prefix set#30456

Merged
encukou merged 6 commits into
python:mainfrom
encukou:cacheprefix-slash
Aug 18, 2025
Merged

bpo-38735: Don't fail when importing from / with sys.pycache_prefix set#30456
encukou merged 6 commits into
python:mainfrom
encukou:cacheprefix-slash

Conversation

@encukou

@encukou encukou commented Jan 7, 2022

Copy link
Copy Markdown
Member

This fixes the issue, but testing it would require putting a file in the root directory.

https://bugs.python.org/issue38735

gh-#82916

@github-actions

github-actions Bot commented Feb 7, 2022

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 7, 2022
@serhiy-storchaka

Copy link
Copy Markdown
Member

You can test it without writing a file.

>>> from importlib.util import cache_from_source
>>> import os
>>> os.chdir('/')
>>> cache_from_source('spam.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    cache_from_source('spam.py')
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 558, in cache_from_source
IndexError: string index out of range

@encukou encukou merged commit d8a9466 into python:main Aug 18, 2025
41 checks passed
@encukou encukou deleted the cacheprefix-slash branch August 18, 2025 11:53
@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 18, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 18, 2025
…et (pythonGH-30456)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 18, 2025
…et (pythonGH-30456)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app

bedevere-app Bot commented Aug 18, 2025

Copy link
Copy Markdown

GH-137905 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 18, 2025
@bedevere-app

bedevere-app Bot commented Aug 18, 2025

Copy link
Copy Markdown

GH-137906 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 18, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…et (pythonGH-30456)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app

bedevere-app Bot commented Sep 18, 2025

Copy link
Copy Markdown

GH-137905 is a backport of this pull request to the 3.13 branch.

@bedevere-app

bedevere-app Bot commented Sep 18, 2025

Copy link
Copy Markdown

GH-137906 is a backport of this pull request to the 3.14 branch.

encukou added a commit that referenced this pull request Sep 18, 2025
…efix set (GH-30456) (GH-137905)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
encukou added a commit that referenced this pull request Oct 7, 2025
…efix set (GH-30456) (GH-137906)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants